﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShadowPool : MonoBehaviour {

    public static ShadowPool Instance;

    public GameObject shadowPrefab;
    public int poolCount;
    private Queue<GameObject> shadowQueue = new Queue<GameObject>();

    private void Awake()
    {
        Instance = this;
        FillPool();
    }

    public void FillPool()
    {
        for (int i = 0; i < poolCount; i++)
        {
            GameObject g = Instantiate(shadowPrefab, transform);
            ReturnPool(g);
        }
    }

    public void ReturnPool(GameObject g)
    {
        g.SetActive(false);
        shadowQueue.Enqueue(g);
    }

    public GameObject GetFromPool()
    {
        if (shadowQueue.Count == 0)
        {
            FillPool();
        }
        GameObject g = shadowQueue.Dequeue();
        g.SetActive(true);
        return g;
    }
}
